package com.liuqi.aiagent;

import com.liuqi.aiagent.util.StringUtil;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author liuqi
 * @date 2025/7/11 17:08
 **/
@SpringBootApplication
public class StartAiAgentApplication {

    private final static String PROPERTIES_CONFIG_KEY = "ai_agent_config";

    // -Dai_agent_config=C:\liuqi-ai-project\moth-ai-agent\ai-agent\src\main\resources\ai_agent.properties
    public static void main(String[] args) throws IOException {
        init(); // 初始化项目

        SpringApplication.run(StartAiAgentApplication.class, args);
    }

    private static void init() throws IOException {
        String config = System.getProperty(PROPERTIES_CONFIG_KEY);
        if (config == null) {
            throw new NullPointerException("未指定配置文件[ai_agent.properties], 参考：-Dai_agent_config=/*/ai_agent.properties");
        }
        Properties properties = new Properties();
        properties.load(new FileInputStream(config));

        properties.forEach((key, value) -> {
            if (StringUtil.hasText(key.toString())) {
                System.setProperty(key.toString(), value.toString());
            }
        });
    }
}
